//
//  MyTableViewCell.m
//  图片故事
//
//  Created by 大帅逼 on 16/1/18.
//  Copyright © 2016年 helloApp. All rights reserved.
//

#import "MyTableViewCell.h"
#import "UIImageView+WebCache.h"
#import "Header.h"
#import "LocaData.h"
#define MAEGIN 10

@interface MyTableViewCell ()

@property(nonatomic,strong) UIImageView         *userHeadImage;
@property(nonatomic,strong) UILabel             *userNameLabel;
@property(nonatomic,strong) UILabel             *userIdLabel;

@end

@implementation MyTableViewCell


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {

    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
     
        // 初始化界面
        _userHeadImage = [[UIImageView alloc] init];
        
        [_userHeadImage setImage:[UIImage imageNamed:@"head_icon"]];
        
        [_userHeadImage.layer setCornerRadius:5];
        
        [_userHeadImage.layer setMasksToBounds:YES];
        
        [self.contentView addSubview:_userHeadImage];
        
        _userNameLabel = [[UILabel alloc] init];
        
        [self.contentView addSubview:_userNameLabel];
     
        _userIdLabel = [[UILabel alloc] init];
        
        [_userIdLabel setText:@"你还没有登录~"];
        
        [_userIdLabel setTextColor:[UIColor grayColor]];
        
        [self.contentView addSubview:_userIdLabel];
        
    }
    
    return self;
}

- (void)layoutSubviews {

    [super layoutSubviews];
    
    // 初始化控件位置
    [_userHeadImage setFrame:CGRectMake(My_Width(MAEGIN), My_Height(MAEGIN), My_Height(60), My_Height(60))];
    
    [_userIdLabel setFrame:CGRectMake(My_Width(100), My_Height(MAEGIN), SCREEN_W - 200, My_Height(20))];
    
    [_userNameLabel setFrame:CGRectMake(My_Width(100), My_Height(MAEGIN) + My_Height(30), SCREEN_W - My_Width(200), My_Height(20))];
}

- (void)setUserInfo:(UserInfoModal *)userInfo {

    _userInfo = userInfo;
    
    // 设置数据
    if ([LocaData isLogin] == NO) {
        
        [_userHeadImage setImage:[UIImage imageNamed:_userInfo.userHead]];

    } else {
        
        [_userHeadImage sd_setImageWithURL:[NSURL URLWithString:_userInfo.userHead]];
        
    }
    
//    [_userNameLabel setText:_userInfo.userName];
    
    [_userIdLabel setText:_userInfo.userName];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
}

@end
